package com.hzlj.position.locate.differentiation.sysCheck;

import com.google.common.collect.Lists;
import com.hzlj.position.locate.common.dto.position.PositionKeyDTO;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public interface SysCheck {

    @Data
    class ReLocateCount {
        private Integer totalCount;
        private AtomicInteger count = new AtomicInteger(0);
        private List<PositionKeyDTO> positionKeys = Lists.newArrayList();

        public ReLocateCount() {
        }

        public ReLocateCount(Integer totalCount) {
            this.totalCount = totalCount;
        }

        public boolean hasRecord() {
            return count.get() != 0;
        }

        /**
         * 返回是否可以继续重试
         */
        public boolean incr(PositionKeyDTO positionKey) {
            boolean incr = count.getAndIncrement() < totalCount;
            positionKeys.add(positionKey);
            return incr;
        }

        public List<PositionKeyDTO> getPositionKeys() {
            return positionKeys;
        }
    }

    @Data
    @Accessors(chain = true)
    class Retry {
        private boolean retry;
        private int minutes = 0;

        public static Retry of(boolean retry) {
            Retry r = new Retry();
            r.setRetry(retry);
            return r;
        }

        public static Retry of(boolean retry, int minutes) {
            Retry r = new Retry();
            r.setRetry(retry);
            r.setMinutes(minutes);
            return r;
        }
    }
}
